
import pandas as pd
import os
import shutil
from pathlib import Path

def process_dataframe():
    df = pd.read_excel("file_map_int.xlsx")
    df = df[(df["file_type"] == 1) & (df["duplicates"] == 0)]
    df["new_pdf"] = df["file_origin_local"].str.replace('|', '_', regex=False) + "_" + df[
        "file_name_origin"].str.replace(".pdf", "", regex=False)
    df_name = df["file_origin_local"].tolist()
    df_name1 = df["file_name_origin"].tolist()
    print(len(df_name), len(df_name1))
    new_name = [str(a).replace("\\", "_") + "_" + str(b).replace(".pdf", "") for a, b in zip(df_name, df_name1)]
    old_name = [str(a).replace(".pdf", "") for a in df["file_name"].tolist()]
    # for a, b in zip(old_name, new_name):
        # print(a, b)
    return old_name, new_name

def move_function():
    directory = r"F:\20250414-v2"
    save_path = r"F:\new"
    old_name,new_name = process_dataframe()
    for root, dirs, files in os.walk(directory):
        for filename in files:
            if Path(filename).stem in old_name:
                filepath = os.path.join(root, filename)
                index = old_name.index(Path(filename).stem)
                new_path = os.path.join(save_path,new_name[index]+Path(filename).suffix)
                shutil.copy(filepath, new_path)

def check_function():
    old_name,new_name = process_dataframe()
    directory = r"E:\llm\data_file\20250414-v3"
    use_idx = []
    for root, dirs, files in os.walk(directory):
        for filename in files:
            # print(filename)
            # 构造完整的文件路径
            name = Path(filename).stem
            idx = new_name.index(name)
            use_idx.append(idx)
    un_use_name = [item for idx,item in enumerate(old_name) if idx not in use_idx]
    print(len(un_use_name),un_use_name)

if __name__ == '__main__':
    check_function()